{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "37092183",
   "metadata": {},
   "source": [
    "# list 列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "86e1fe33",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "l = [1,2,3]\n",
    "l.append(4)\n",
    "l"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ca4b7a1d",
   "metadata": {},
   "source": [
    "列表元素可以是列表并追加"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "ab1b1cf0",
   "metadata": {},
   "outputs": [],
   "source": [
    "l2 = [5,6,7]\n",
    "l3 = []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "144dce06",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[1, 2, 3, 4], [5, 6, 7]]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "l3.append(l)\n",
    "l3.append(l2)\n",
    "l3"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9324e54d",
   "metadata": {},
   "source": [
    "过滤None元素"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1e8cb65a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, None, 4, None, None, 5, 8, None]\n",
      "[1, 4, 5, 8]\n"
     ]
    }
   ],
   "source": [
    "test_list = [1, None, 4, None, None, 5, 8, None] \n",
    "\n",
    "# 输出原始列表\n",
    "\n",
    "print(str(test_list));\n",
    "\n",
    " \n",
    "#使用filter()函数，删除列表中的None值\n",
    "\n",
    "res = list(filter(None, test_list)) \n",
    " \n",
    "\n",
    "# 输出新的列表\n",
    "\n",
    "print (str(res ))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "71de6d13",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
